from Components.Language import language
from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_LANGUAGE
import os, gettext
PluginLanguageDomain = "FreePlayer"
PluginLanguagePath = "Extensions/FreePlayer/po"

def localeInit():
	lang = language.getLanguage()[:2]
	os.environ["LANGUAGE"] = lang
	print "[FP] set language to ", lang
	gettext.bindtextdomain(PluginLanguageDomain, resolveFilename(SCOPE_PLUGINS, PluginLanguagePath))

def _(txt):
	t = gettext.dgettext(PluginLanguageDomain, txt)
	if t == txt:
		#print "[FP] fallback to default translation for", txt
		t = gettext.gettext(txt)
	return t

localeInit()
language.addCallback(localeInit)

fonts_path = "/usr/share/fonts"
file_name = "/usr/lib/enigma2/python/Plugins/Extensions/FreePlayer/font.ini"

f = open(file_name,'w')

for file in os.listdir(fonts_path):
    if file.endswith(".ttf") or file.endswith(".TTF"):
        f.write(file+'\n')

f.close()